package com.yanqu.road.server.cmd.union.activitygroup;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.union.UnionActivityGroupProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C2_UNION_ACTIVITY_GET_USER_INFO_BACK, desc = "拿玩家基础数据(返回)")
public class CrossGetUserBaseInfoBackCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        UnionActivityGroupProto.CrossGetUserBaseInfoRespMsg respMsg = UnionActivityGroupProto.CrossGetUserBaseInfoRespMsg.parseFrom(packet.getBytes());
        for (UnionActivityGroupProto.CrossUserBaseInfoTemp infoTemp : respMsg.getUserList()) {
            UserBaseInfo userBaseInfo = PlayerBasePb.parseToUserBaseInfo(infoTemp.getBaseInfo());
            if(userBaseInfo != null){
                CrossUserMgr.getLogger().info("update baseInfo {}", infoTemp.getUserId());
                CrossUserMgr.updateUserBaseInfo(infoTemp.getUserId(), userBaseInfo);
            }
        }
    }

    @Override
    public void sendData() {

    }
}
